﻿using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Xms.Abp.Identity;
using Volo.Abp.Users;

namespace Xms.Abp.OperationLogging;

[Dependency(TryRegister = true)]
public class NullOperationLoggingManager : IOperationLoggingManager, ITransientDependency
{
    protected ICurrentUser CurrentUser { get; }
    protected ILogger<NullOperationLoggingManager> Logger { get; }
    public NullOperationLoggingManager(
        ICurrentUser currentUser,
        ILogger<NullOperationLoggingManager> logger)
    {
        CurrentUser = currentUser;
        Logger = logger;
    }
    public virtual async Task AddAsync(string operation, string message, string source, string target, IUser user = null)
    {
        if (user != null)
        {
            Logger.LogInformation($"Operation:{operation}, Message:{message}, Source:{source}, Target:{target}, User:{user.UserName}");
        }
        else
        {
            Logger.LogInformation($"Operation:{operation}, Message:{message}, Source:{source}, Target:{target}, User:{CurrentUser.UserName}");
        }
        await Task.CompletedTask;
    }
}

